package ochart.core
{
	import ochart.chartClasses.IChartObject;
	import ochart.elements.areas.Area;
	import ochart.elements.axes.RightYAxis;
	import ochart.elements.axes.Tick;
	import ochart.elements.axes.XAxis;
	import ochart.elements.axes.YAxis;
	import ochart.elements.background.Background;
	import ochart.elements.bars.Bar;
	import ochart.elements.labels.DataTip;
	import ochart.elements.labels.Label;
	import ochart.elements.labels.Title;
	import ochart.elements.lines.Line;
	import ochart.elements.pies.Pie;
	import ochart.elements.radars.Radar;
	
	public class ChartObjectFactory
	{
		private static var _instance:ChartObjectFactory = null;
		
		public static function get instance():ChartObjectFactory
		{
			if(!_instance)
			{
				_instance = new ChartObjectFactory();
			}
			return _instance;
		}
		
		public function ChartObjectFactory()
		{
		}
		
		public function create(name:String):IChartObject
		{
			var object:IChartObject = null;
			object = createByAlis(name);
			if(!object)
			{
				object = createByClassName(name);
			}
			return object;
		}
		
		public function createByAlis(alias:String):IChartObject
		{
			return createByClassName(getClassNameByAlis(alias));
		}
		
		public function createByClassName(className:String):IChartObject
		{
			switch(className)
			{
				case XYChart.CLASS_NAME:
					return new XYChart();
				case PieChart.CLASS_NAME:
					return new PieChart();
				
				case Area.CLASS_NAME:
					return new Area();
				case Bar.CLASS_NAME:
					return new Bar();
				case Line.CLASS_NAME:
					return new Line();
				case Pie.CLASS_NAME:
					return new Pie();
				case Radar.CLASS_NAME:
					return new Radar();
				
				case Background.CLASS_NAME:
					return new Background();
				case DataTip.CLASS_NAME:
					return new DataTip();
				case Label.CLASS_NAME:
					return new Label();
				case Tick.CLASS_NAME:
					return new Tick();
				case Title.CLASS_NAME:
					return new Title();
					
				case XAxis.CLASS_NAME:
					return new XAxis();
				case YAxis.CLASS_NAME:
					return new YAxis();
				case RightYAxis.CLASS_NAME:
					return new RightYAxis();
			}
			return null;
		}
		
		public static function getClassNameByAlis(alias:String):String
		{
			switch(alias)
			{
				case XYChart.ALIAS:
					return XYChart.CLASS_NAME;
				case PieChart.ALIAS:
					return PieChart.CLASS_NAME;
				
				case Area.ALIAS:
					return Area.CLASS_NAME;
				case Bar.ALIAS:
					return Bar.CLASS_NAME;
				case Line.ALIAS:
					return Line.CLASS_NAME;
				case Pie.ALIAS:
					return Pie.CLASS_NAME;
				case Radar.ALIAS:
					return Radar.CLASS_NAME;
				
				case Background.ALIAS:
					return Background.CLASS_NAME;
				case DataTip.ALIAS:
					return DataTip.CLASS_NAME;
				case Label.ALIAS:
					return Label.CLASS_NAME;
				case Tick.ALIAS:
					return Tick.CLASS_NAME;
				case Title.ALIAS:
					return Title.CLASS_NAME;
					
				case XAxis.ALIAS:
					return XAxis.CLASS_NAME;
				case YAxis.ALIAS:
					return YAxis.CLASS_NAME;
				case RightYAxis.ALIAS:
					return RightYAxis.CLASS_NAME;
			}
			return null;
		}
	}
}